package cn.zwxky.android.staff.Utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.zgscwjm.lsfbbasetemplate.Event.LsfbEvent;
import com.zgscwjm.lsfbbasetemplate.utils.LsfbLog;
import com.zgscwjm.lsfbbasetemplate.utils.T;

import cn.zwxky.android.staff.BusinessAddList.ChaoShiEvent;


public class myProgressDialog {
	private  Context mcontext;
   private ProgressDialog mydialog;
	private int time=10;
	private  Boolean forever=false;
	private String mtips;
	private Handler handler=new Handler(){
		@Override
		public void dispatchMessage(Message msg) {
			super.dispatchMessage(msg);
			switch (msg.what)
			{
				case 1:
					if (mydialog.isShowing() && mydialog!=null) {
						hidedialog();
						T.showShort(mcontext, "网络请求超时");
						LsfbLog.e("等待匡超时"+mtips);
//						LsfbLog.e("等待匡超时"+CommonUtils.getActivityName(mcontext)+"*************************");

						LsfbEvent.getInstantiation().post(new ChaoShiEvent<String>("chaoshi"));
					}
					break;
			}
		}
	};
	public myProgressDialog(Context context, String tips) {
		mydialog = new ProgressDialog(context);
		mcontext=context;
		forever=false;
		time=10;
		mydialog.setMessage(tips);
		mtips=tips;
		mydialog.setCancelable(false);
	}
	public myProgressDialog(Context context, String tips, int time) {
		mydialog = new ProgressDialog(context);
		mcontext=context;
		mydialog.setMessage(tips);
		forever=false;
		mydialog.setCancelable(false);
		this.time=time;
	}
	public myProgressDialog(Context context, String tips, Boolean forever) {
		mydialog = new ProgressDialog(context);
		mcontext=context;
		mydialog.setMessage(tips);
		mydialog.setCancelable(false);
		this.forever=forever;
	}

	public void showdialog(){
		if (mydialog!=null && !mydialog.isShowing())
		{
		mydialog.show();
			LsfbLog.e(LittleUtils.getActivityName(mcontext)+"**********************----------------------");
			if (!forever) {
				handler.sendEmptyMessageDelayed(1, time * 1000);
			}
		}
	}
	public void hidedialog(){
		if (mydialog!=null && mydialog.isShowing()) 
		{
			mydialog.dismiss();
		}
	}
	

}
